/**
 * @file   1086.cpp
 * @author Shuang Hu <hsmath@ubuntu>
 * @date   Sat Apr 24 04:08:03 2021
 * 
 * @brief  PAT Problem1086, Tree Traversals
 * 
 * 
 */
#include<iostream>
#include<string>
#include<vector>
using namespace std;
class TreeTraversal{
private:
    vector<int> preorder;
    vector<int> inorder;
    vector<int> postorder;
    int Nodenum;
public:
    TreeTraversal(int N);
    void solve(int preL,int inL,int postL,int num);
    void print(){
	cout<<postorder[0];
	for(int i=1;i<Nodenum;i++){
	    cout<<" "<<postorder[i];
	}
	cout<<endl;
    }
};
TreeTraversal::TreeTraversal(int N){
    Nodenum=N;
    vector<int> stack;
    for(int i=0;i<2*N;i++){
	string s;
	int k;
	cin>>s;
	if(s=="Push"){
	    cin>>k;
	    stack.push_back(k);
	    preorder.push_back(k);
	}
	else{
	    inorder.push_back(stack[stack.size()-1]);
	    stack.pop_back();
	}
    }
    postorder.resize(N);//Postorder sequence has N nodes!
}
void TreeTraversal::solve(int preL,int inL,int postL,int num){
    if(num==0){
	return;
    }
    if(num==1){
	postorder[postL]=preorder[preL];
	return;
    }
    int i;
    int root=preorder[preL];
    postorder[postL+num-1]=root;//Mark the root node!
    for(i=0;i<num;i++){
	if(inorder[inL+i]==root){
	    break;
	}
    }
    int L=i;
    int R=num-L-1;
    solve(preL+1,inL,postL,L);
    solve(preL+L+1,inL+L+1,postL+L,R);
}
int main(){
    int N;
    cin>>N;
    TreeTraversal T(N);
    T.solve(0,0,0,N);
    T.print();
}
